import { getUnitList } from '@/api/unit'

const state = {
  unit: {}
}
const mutations = {
  SET_UNIT_LIST(state, unitList) {
    state.unit = unitList
  }

}
const actions = {
  getUnitList({ commit }, queryVo) {
    return new Promise((resolve, reject) => {
      getUnitList(queryVo).then(response => {
        const { data } = response

        if (!data) {
          return reject('get unitList fail')
        }

        const { unitList } = data

        commit('SET_UNIT_LIST', unitList)

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
